const { defineConfig } = require('@vue/cli-service')
const config = require('./package.json')
module.exports = defineConfig({
  // publicPath: './',
  // assetsDir: 'assets',
  productionSourceMap: false,//去除生产环境的sourceMap文件
  chainWebpack(config) {
    config.optimization.minimizer('terser').tap((args) => {
      args[0].parallel = 4
      args[0].terserOptions.compress.warnings = true
      // args[0].terserOptions.compress.drop_debugger = true
      // args[0].terserOptions.compress.drop_console = true
      return args
    })
  },
  pluginOptions: {
    electronBuilder: {
      customFileProtocol: "./",
      chainWebpackMainProcess: (config) => {
        config.output.filename((file) => {
          if (file.chunk.name === 'index') {
            return 'background.js';
          } else {
            return '[name].js';
          }
        });
      },
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,
      builderOptions: {
        publish: {
          provider: "generic",
          url: process.env.VUE_APP_UPDATEURL,
          channel: process.env.VUE_APP_LATEST_NAME,
        },
        extraResources: [
          { from: './public/index.html', to: './' },
          { from: './static', to: '../static/' },
          { from: './src/assets', to: 'assets' },
        ],
        appId: process.env.VUE_APP_APPID,
        productName: process.env.VUE_APP_PRODUCT_NAME,
        nsis: {
          oneClick: false, // 一键安装
          perMachine: true, // 是否开启安装时权限限制（此电脑或当前用户）
          allowElevation: true, // 允许请求提升。 如果为false，则用户必须使用提升的权限重新启动安装程序。
          allowToChangeInstallationDirectory: true, // 允许修改安装目录
          installerIcon: `./public/logo${config.version}.ico`, // 安装图标
          uninstallerIcon: `./public/logo${config.version}.ico`, //卸载图标
          installerHeaderIcon: `./public/logo${config.version}.ico`, // 安装时头部图标
          createDesktopShortcut: true, // 创建桌面图标
        },
        win: {
          icon: `./public/logo${config.version}.png`, //图标路径,
          target: [{
            target: 'nsis', // 利用nsis制作安装程序
            'arch': [
              // 'x64', // 64位
              'ia32'
            ]
          }]
        },
      },
    },
  },
})
